package com.xbh.common.utils;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;

import java.util.Random;

/**
 * @program: common-utils
 * @description:
 * @author: 许宝华
 * @create: 2021-09-04 09:33
 */

public class IdGeneratorService implements IdentifierGenerator {


    private final char[] arrays = {'0','1','2','3','4','5','6','7','8','9'};

    private final Random random = new Random();


    @Override
    public Number nextId(Object entity) {

        long ops =  0L;
        for (int i = 0; i < 15; i++) {
            int tmp = random.nextInt(9)+1;
            ops = ops * 10 + tmp;
        }
        return ops;

    }

    @Override
    public String nextUUID(Object entity) {

        StringBuffer buffer = new StringBuffer();
        String name = entity.getClass().getSimpleName().toLowerCase();
        buffer.append(name).append("-");
        for (int i = 0; i < 9; i++) {
            buffer.append(arrays[random.nextInt(26) + 10]);
            buffer.append(arrays[random.nextInt(10)]);
        }
        return buffer.toString();
    }
}
